#pragma once
#include <vector>
#include <iostream>

struct Particle
{
	std::vector<float> pos;
	std::vector<float> v;
	std::vector<float> bestPos;
	float bestF;
};

class ParticleSwarm
{
public:
	typedef float (*FitnessFunc)(float*);
	ParticleSwarm(FitnessFunc fitnessFunc, size_t dim, size_t nParticles, float minPos, float maxPos);
	void step();
	const float* getBest() const;
	float getBestFitness() const;
	size_t getIterationCount() const;
	void save(std::ostream& f);
	void load(std::istream& f);
private:
	void calcFitness();
	void move();
	FitnessFunc fitnessFunc;
	size_t dim;
	float minPos;
	float maxPos;
	float maxV;
	float c1;
	float c2;
	float ksi;
	size_t bestParticle;
	size_t iterationCount;
public:
	std::vector<Particle> particles;
};
